// Copyright (c) 2009-2015 Intel Corporation
// All rights reserved.
//
// WARRANTY DISCLAIMER
//
// THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE
// MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Intel Corporation is the author of the Materials, and requests that all
// problem reports or change requests be submitted to it directly

#ifndef OCL_H
#define OCL_H

#include <CL/cl.h>
#include <Windows.h> //needed to make DX11 header inclusion errors go away

#include <CL/cl_d3d11.h> 

#include <string.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>

//#include "common_CL_DX11.h"

#define CL_DEVICE_CPU_OR_GPU CL_DEVICE_TYPE_GPU
//#define CL_DEVICE_CPU_OR_GPU CL_DEVICE_TYPE_CPU

#define SUCCESS 0
#define FAIL -1

//will be replaced with real video resolution
//#define SHARED_IMAGE_HEIGHT 240
//#define SHARED_IMAGE_WIDTH 192

#define SHARED_IMAGE_HEIGHT 64
#define SHARED_IMAGE_WIDTH 64


//#define CL_KERNELS "ocl_rotate.cl"
#define CL_KERNELS "OpenCLRGBAFile.cl"


//FOR SHARING
extern cl_mem		g_SharedNV12imageCLMemObject_Y;
extern cl_mem		g_SharedNV12imageCLMemObject_UV;
extern bool			g_UseD3D11_RESOURCE_MISC_SHAREDflag;

//verification if support for surface sharing exists
int VerifyCLDX11SurfaceSharingPlatformAvailableCL();
int UseD3D11_RESOURCE_MISC_SHAREDFlagCL(); //returns TRUE if sharing is faster with this flag on surface creation on DX11 side

//entry point for initialization of CL platform, creation of context, queue, etc.
int InitCL(void);
//compile program and create kernels to be used on device side
int InitDeviceCodeCL();

//CL/DX11 sharing, major API call for this tutorial
int GetDX11SharingFunctionsFromCL();
int ShareDX11BufferWithCL(ID3D11Texture2D* g_pSharedDX11Texture2D);
//int ShareDX11BufferWithCL();
int ReleaseSharedDX11BufferWithCL();

//run per frame
void SimulateCL();
int ExitCL(void);

//Debugging functions
int handleCompileError(void);
int convertToString(const char *filename, char *buf);

//utility functions
//testStatus is simplified to minimize extraneous code in a sample
void testStatus(int status, char *errorMsg);

extern ID3D11Device*	g_pd3dDevice;

#endif OCL_H
